package com.bike.controller.information;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bike.controller.BaseController;
import com.bike.entity.HhFoodTag; 
import com.bike.util.PageData;
import com.bike.service.impl.HhFoodTagServiceImpl;

 
@Controller
@RequestMapping(value="/hhFoodTag")
public class HhFoodTagController extends BaseController {
	
		@Autowired
		private HhFoodTagServiceImpl  hhFoodTagService;
	
		/**
		 * 跳转到列表页面
		 */
		@RequestMapping("toList")
		public String toList(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			model.addAttribute("pd", pd);
			return "/information/foodTag/hhFoodTag_list";
		}
		/**
		 * 列表查询(或根据条件)
		 */
		@RequestMapping("list")
		@ResponseBody
		public PageData list(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			return hhFoodTagService.selectHhFoodTagList(pd);
		}
		/**
		 * 列表查询(或根据条件)
		 */
		@RequestMapping("listAll")
		@ResponseBody
		public PageData listAll(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			return hhFoodTagService.selectHhFoodTagList(pd);
		}
		/**
		 * 跳转到编辑页面（新增和修改）
		 */
		@RequestMapping("toEdit")
		public String toEdit(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			model.addAttribute("pd", pd);
			if(pd.getLong("foodTagId")>0){
				model.addAttribute("pd", hhFoodTagService.selectByHhFoodTagId(pd.getLong("foodTagId")));
			} 
			return "/information/foodTag/hhFoodTag_edit";
		}
		/**
		 * 搜素
		 * @param request
		 * @param model
		 * @return
		 */
		@RequestMapping("toSearch")
		public String toSearch(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			model.addAttribute("pd", pd);
			return "/information/foodTag/hhFoodTag_search";
		}
		/**
		 * 新增和修改 
		 */
		@RequestMapping("save")
		@ResponseBody
		 public Map<String,Object> save(HttpServletRequest request,HhFoodTag hhFoodTag){
			try {
				PageData pd=PageData.getPageDataByPage(request);
				hhFoodTagService.saveOrUpdate(pd,hhFoodTag);
				return getSuccessMap();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return getErrorMap("失败");
		 }
		/**
		 * 删除
		 */
	 	@RequestMapping("delete")
		@ResponseBody
		 public Map<String,Object> delete(HttpServletRequest request){
			try {
				PageData pd=PageData.getPageDataByPage(request);
				if(pd.getLong("foodTagId")>0){
					hhFoodTagService.deleteHhFoodTagById(pd.getLong("foodTagId"));
					return getSuccessMap();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return getErrorMap("失败");
		}
	 	@RequestMapping("getMutliType")
	 	@ResponseBody
	 	public Map<String,Object> getMutliType(HttpServletRequest request){
	 		try {
	 			PageData pd=PageData.getPageDataByPage(request);
	 			if(pd.getLong("foodId")>0){
	 				Map<String,Object> result=getSuccessMap();
	 				result.put("foodTags", hhFoodTagService.selectByFoodId(pd.getLong("foodId")));
	 				return result;
	 			}
	 		} catch (Exception e) {
	 			e.printStackTrace();
	 		}
	 		return getErrorMap("失败");
	 	}
}
